import Code from 'components/Markdown/Code'
import Warning from 'components/Markdown/Warning'

export const meta = {
  title: "Database Connector (Postgres)",
  position: 50,
  technology: "postgres",
  technologyOrder: 2,
  articleGroup: "Database Connector"
}

## Overview

A database connector is the _link_ between Prisma and the underlying database. 
The Postgres connector is used to connect a Prisma server to a [PostgreSQL](https://www.postgresql.org/) database. 

The core responsibilities of a database connector are:

- Translate incoming GraphQL queries into SQL
- Generate responses according 
- Perform database migrations (optional)

When configuring your Prisma server with Docker, you need to specify which connector you'd like to use in order to connect to a certain database. You provide this info via the `connector` property:

<Code language="yml" lines="6">

```yml
PRISMA_CONFIG: |
  managementApiSecret: __YOUR_MANAGEMENT_API_SECRET__
  port: 4466
  databases:
    default:
      connector: postgres
      migrations: __ENABLE_DB_MIGRATIONS__
      host: __YOUR_DATABASE_HOST__
      port: __YOUR_DATABASE_PORT__
      user: __YOUR_DATABASE_USER__
      password: __YOUR_DATABASE_PASSWORD__
      connectionLimit: __YOUR_CONNECTION_LIMIT__
```

</Code>

## Migrations

The `migrations` property in the `PRISMA_CONFIG` environment variable specifies whether the database connector is able to make changes to the underlying _database schema_.

For existing databases (that might already be powering production applications), it is useful to configure the Prisma server to not migrate the connected database. This ensures you're not accidentally introducing unwanted schema changes or lose data.

<Code language="yml" lines="7">

```yml
PRISMA_CONFIG: |
  managementApiSecret: __YOUR_MANAGEMENT_API_SECRET__
  port: 4466
  databases:
    default:
      connector: postgres
      migrations: __ENABLE_DB_MIGRATIONS__
      host: __YOUR_DATABASE_HOST__
      port: __YOUR_DATABASE_PORT__
      user: __YOUR_DATABASE_USER__
      password: __YOUR_DATABASE_PASSWORD__
      connectionLimit: __YOUR_CONNECTION_LIMIT__
```

</Code>


### Enabling and disabling database migrations

If `migrations` is set to `true`, deploying a Prisma service migrates the structure of the connected database. In these cases, the Prisma CLI will be the main interface to govern the structure of the database based on the datamodel of your Prisma services.

If `migrations` is set to `false`, the database schema is "locked" and Prisma won't perform any changes on it.

## Managing database connections

The `connectionLimit` property in `PRISMA_CONFIG` determines the number of database connections a Prisma service is going to use.

<Warning>

The `connectionLimit` needs to be set to at least **2**. One connection is always reserved for the [Management API](foe1), all other connections are used for the Prisma service.

</Warning>